const state = {
    token:''
}
const mutations = {
    setToken(state,data){
        state.token = data
    }
}
const actions = {
   async fetchToken({commit}){
        
    //获取用户基本信息
      const [err, res] = await uni.getUserProfile({ desc: "用于後續服務" });
      const [err1, resCode] = await uni.login();
      const { encryptedData, rawData, iv, signature } = res;
      const { code } = resCode;
      //获取token
      const resToken = await uni.$u.http.post("/users/wxlogin", {
        encryptedData,
        rawData,
        iv,
        signature,
        code,
      });
      const { token } = resToken;
      commit("setToken",token)
    }
}

const getters = {
    token(state){
        return state.token
    }
}

export default {
    namespaced:true,
    state,
    mutations,
    actions,
    getters
}